#include "stdafx.h"
#include "Utils\Log.h"
#include <stdarg.h>

CLog::CLog()
{
	mLogFileName  = "C:\\Log.txt";
}



CLog::CLog(char* fileName)
{
	 //ASSERT(fileName);

	 mLogFileName  = fileName;

}


CLog::~CLog()
{

}



void  CLog::Log(char * format, ...)
{
	FILE* fp;
	char formatContext[256];
	int  ret  = 0;
	va_list args;

	fopen_s(&fp, mLogFileName.c_str(), "a+");
	

	va_start(args, format);

	ret  = vsnprintf_s(formatContext,  256, format, args);

	va_end(args);

	fwrite(formatContext, ret, 1, fp);

	fclose(fp);
}



void CLog::Log(FILE* fileStream, char* format, ...)
{
	//FILE* fp;
	char formatContext[256];
	int  ret = 0;
	va_list args;

	//fopen_s(&fp, mLogFileName.c_str(), "a+");


	va_start(args, format);

	ret = vsnprintf_s(formatContext, 256, format, args);

	va_end(args);

	fwrite(formatContext, ret, 1, fileStream);

	//fclose(fp);
}


void CLog::SetLogFile(char* file)
{
	mLogFileName  = file;
}